<?php
/*
 +----------------------------------------------------------------------
 + Title        : DictController 控制器
 + Author       : Randy_chen
 + Version      : V1.0.0.1
 + Initial-Time : 2023/7/8 22:44
 + Last-time    : 2023/7/8 22:44+ chen2
 + Desc         : DictController
 +----------------------------------------------------------------------
*/


namespace app\api\controller\common;

use app\BaseController;
use app\common\model\Dict;

class DictController
{
    public function index()
    {
        $list = Dict::select()
                    ->toArray();
        $arr = [];

        foreach ($list as $k => $v) {
            if ($v['pid'] == 0) {
                $arr[] = [
                    'filed' => $v['data_type'],
                    'label' => $v['data_name']
                ];
                unset($list[$k]);
            }
        }
        foreach ($arr as &$vv) {
            foreach ($list as $kkk => $vvv) {
                if ($vv['filed'] == $vvv['data_type']) {
                    $vv['values'][] = $vvv;
                    unset($list[$kkk]);
                }
            }
        }
        return json($arr);
    }
}